package org.ssm.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.ssm.pojo.User;
import org.ssm.pojo.UserType;
import org.ssm.service.UserService;
import org.ssm.service.UserTypeService;
import org.ssm.util.PageTool;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    @Resource
    UserService userService;
    @Resource
    UserTypeService userTypeService;

    @RequestMapping("/list")
public String list(Model model, User user){

    int totalRecordCount=userService.getRecordCount(user);
    PageTool pageTool=new PageTool(totalRecordCount,user.getCurrPageNo(),5);
    int startNum=pageTool.getStartRow();
    int pageSize=pageTool.getPageSize();
    user.setStarNum(startNum);
    user.setPageSize(pageSize);

    List<User> list=userService.getUserListByPage(user);
    List<UserType> plist=userTypeService.getAllUserTypeList();

    model.addAttribute("list",list);
    model.addAttribute("plist",plist);
    model.addAttribute("user",user);
    model.addAttribute("pageTool",pageTool);

    model.addAttribute("prePages",pageTool.getPrePages());
    model.addAttribute("nextPages",pageTool.getNextPages());


    return "/user/list";
}


}
